package com.lk.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * 配置cors
 *
 * @author : com.com.lk
 * @date 2021/11/21 18:28
 **/
@Configuration
public class CorsConfig {
    public static final String ALL = "*";

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedHeader(ALL);
        config.addAllowedMethod(ALL);
        config.addAllowedOrigin(ALL);
        config.setAllowCredentials(true);
        configSource.registerCorsConfiguration("/**", config);
        return new CorsWebFilter(configSource);
    }
}
